/*
 * Copyright (C) 2019-2020 Alibaba Group Holding Limited
 */

#include <aos/aos.h>
#include "aos/cli.h"
#include "main.h"
#include "app_init.h"
#include <app_i2c.h>
#include "wm_gpio.h"
#include "wm_gpio_afsel.h"	
#include "wm_hostspi.h"
#include "wm_spi_hal.h"
#define TAG "app"

void TaskSensor(void* priv) {
    while(1) {
        float RawHumidity = ReadSensorHumidity();   
        uint8_t Humidity = (uint8_t)(RawHumidity * 100); // 湿度
        float Temperature = ReadSensorTemperature();     // 温度
        LOGD("Sensro Demo", "Temperature: %f Humidity: %d%%. \n", Temperature, Humidity);
        aos_msleep(1000);
    }
}

void spi_Init(){
	  /*1.IO口配置 */
    wm_spi_ck_config(WM_IO_PB_01);
    wm_spi_do_config(WM_IO_PA_07);   //mosi   主机输出，从机输入
    wm_spi_di_config(WM_IO_PB_00);  // miso   主机输入，从机输出
	wm_spi_cs_config(WM_IO_PA_00);
	
	tls_spi_init();   // 初始化成功了
	tls_spi_trans_type(SPI_DMA_TRANSFER);
	tls_spi_setup(TLS_SPI_MODE_3, TLS_SPI_CS_LOW, TLS_SPI_FCLK_MAX);
}

int main(void) {
	
    board_yoc_init();
    InitializeSensor();	
	spi_Init();
    aos_task_new("sensor", tm1668_test_task, NULL, 1024);
    return 0;
}

